# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     conf
   Description :
   Author :       Jolg
   date：          2021/11/4
-------------------------------------------------
   Change Activity:
                   2021/11/4:
-------------------------------------------------
"""

from loguru import logger
import os
from typing import  Optional
from starlette.templating import Jinja2Templates
from pathlib import Path
from utils.tool import Dict2Obj
from utils.mydb import Mysql

#开发环境
ENV='DEV'

BASE_DIR = Path(__file__).resolve().parent
log_path = os.path.join(BASE_DIR, 'logs')
if not os.path.exists(log_path):
    os.mkdir(log_path)
log_path_error = os.path.join(log_path, f'fastapi.log')
# 日志简单配置
logger.add(log_path_error)


class Config(object):
    DEBUG = False
    APICONF={'title':'Pear Admin FastApi'}
    TITLE='Pear Admin FastApi'
    DESCRIPTION='Pear Admin FastApi'
    VERSION='1.0.0'
    # 文档地址 成产环境可以关闭 None
    DOCS_URL: Optional[str] = "/docs"
    # # 文档关联请求数据接口 成产环境可以关闭 None
    OPENAPI_URL: Optional[str] = "/openapi.json"
    # 禁用 redoc 文档
    REDOC_URL: Optional[str] = "/redoc"

    PORT=8080
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8  # 8 天
    SECRET_KEY: str = '-*&^)()sd(*A%&^aWEQaasda_asdasd*&*)(asd%$#'
    THISHOST='0.0.0.0'

    ACCESS_RECORDS=True

    TOKEN='JKt1zxJ9eatVROXP5D2FzYBTu7FIMxPiCCrBnIoFuVY3pwQMn6dF40dzyoosn0y2'

class ProduConfig(Config):
    HELLO = "【生产环境】"
    DEBUG = False
    MYDB = Dict2Obj({'host': '115.126.92.38',
                     'port': 3306,
                     'dbname': 'fastapidb',
                     'username': 'root',
                     'password': 'flzx3Qc'
                     })

class DevConfig(Config):
    HELLO = "【开发环境】"
    DEBUG = True
    MYDB = Dict2Obj({'host': '115.126.92.38',
                     'port': 3306,
                     'dbname': 'fastapidb',
                     'username': 'root',
                     'password': 'flzx3Qc'
                     })


class TestConfig(Config):
    TESTING = True
    HELLO = "【测试环境】"
    MYDB = Dict2Obj({'host': '115.126.92.38',
                     'port': 3306,
                     'dbname': 'fastapidb',
                     'username': 'root',
                     'password': 'flzx3Qc'
                     })

config =  ProduConfig()  if ENV=='PRO' else DevConfig()

templates = Jinja2Templates(directory="templates")
db=Mysql(**config.MYDB)
def hello():
    print(f'''
======================================
    {config.TITLE}
======================================
''')
    logger.info(config.HELLO)
    thisurl=f"http://{'127.0.0.1' if config.THISHOST=='0.0.0.0' else config.THISHOST }:{config.PORT}"
    logger.info(thisurl)
    logger.info(f'''接口文档地址： {thisurl}{config.DOCS_URL}''')